/*****************************************************************************
 *   Copyright 2005 Tim A Wang
 *
 *   Licensed under the Apache License, Version 2.0 (the "License");
 *   you may not use this file except in compliance with the License.
 *   You may obtain a copy of the License at
 *
 *       http://www.apache.org/licenses/LICENSE-2.0
 *
 *   Unless required by applicable law or agreed to in writing, software
 *   distributed under the License is distributed on an "AS IS" BASIS,
 *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *   See the License for the specific language governing permissions and
 *   limitations under the License.
 *
 ****************************************************************************/
package com.jb.web.bean.event;

import java.util.Enumeration;
import java.util.EventObject;
import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;


public class UIEvent extends EventObject {
    static final long serialVersionUID = 123123L;
    private HashMap map = new HashMap();
    private HttpServletRequest request;

    public UIEvent(Object pSource) {
        super(pSource);
    }
    public String get(String key) {
        return this.getParameter(key);
    }
    public UIEvent(Object pSource, HttpServletRequest request) {
        super(pSource);

        this.request = request;

        Enumeration enumertaion = request.getParameterNames();

        map = new HashMap();

        while (enumertaion.hasMoreElements()) {
            String key = (String) enumertaion.nextElement();
            map.put(key, request.getParameter(key));
        }
    }

    public String getParameter(String pKey) {
        if (request != null) {
            return request.getParameter(pKey);
        } else {
            return null;
        }
    }

    public Map getParameters() {
        return map;
    }

    public HttpServletRequest getRequest() {
        return request;
    }

    public String toString() {
        return getSource().toString();
    }
}
